﻿using System;
using System.Collections.Generic;
using IBNet.UtilsDataStructuresAndExtensions;

namespace IBNet.DayTrade.Indicators
{
   public class ModifiedRateOfChange : Indicator
   {
      private readonly RateOfChange ROCIndicator;

      public ModifiedRateOfChange(int rocLength, PriceBarType barType, string name)
         : base(name)
      {
         this.ROCIndicator = new RateOfChange(rocLength, barType);
      }

      public ModifiedRateOfChange(int rocLength, PriceBarType barType)
         : this(rocLength, barType, "ModifiedRateOfChange")
      {
      }

      public override decimal? CalculateIndicator(FixedLengthCollection<PriceBar> priceBars)
      {
         decimal? thisRocValue = ROCIndicator.CalculateIndicator(priceBars);

         if (!thisRocValue.HasValue)
         {
            return null;
         }

         if (thisRocValue < 0)
         {
            return -66.67m;
         }
         else if (thisRocValue > 0)
         {
            return 66.67m;
         }
         else // thisRocValue == 0
         {
            return 0;
         }
      }
   }
}
